package com.brillilab.service.core.notice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.notice.NoticeReadMapper;
import com.brillilab.domain.po.notice.NoticeRead;
import com.brillilab.domain.vo.lab.LabMemberVo;
import com.brillilab.service.core.notice.INoticeReadService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * 已阅读成员
 * @author wmh
 */
@Service
@Transactional
public class NoticeReadServiceImpl implements INoticeReadService {

    @Resource
    private NoticeReadMapper noticeReadMapper;

    @Override
    public NoticeRead selectOneByNoticeIdAndLabIdAndLabMemberId(Long noticeId,Long labId,Long labMemberId) {
        Assert.isTrue(labId!=null && labMemberId!=null && noticeId!=null,"参数缺失！");
        return noticeReadMapper.selectOne(
                new LambdaQueryWrapper<NoticeRead>()
                        .eq(NoticeRead::getNoticeId,noticeId)
                        .eq(NoticeRead::getLabId,labId)
                        .eq(NoticeRead::getLabMemberId,labMemberId));
    }

    @Override
    public List<LabMemberVo> selectReadMemberList(Long noticeId,Long labId) {
        Assert.isTrue(labId!=null && noticeId!=null,"参数缺失！");
        return noticeReadMapper.selectReadMemberList(noticeId,labId);
    }

    @Override
    public boolean insert(NoticeRead read) {
        Assert.notNull(read,"参数缺失！");
        return noticeReadMapper.insert(read) > 0;
    }
}
